package List;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-02-29
 * Time:14:09
 * Text：25. K 个一组翻转链表
 */
public class Text7 {
    public ListNode reverseKGroup(ListNode head, int k) {
        int num=0;
        ListNode cur=head;
        while(cur!=null){
            num++;
            cur=cur.next;
        }

        ListNode t1=new ListNode(0);
        ListNode t2=t1;
        cur=head;
        for(int i=0;i<num/k;i++){
            ListNode tmp=cur;
            for(int j=0;j<k;j++){
                ListNode t3=cur.next;
                cur.next=t2.next;
                t2.next=cur;
                cur=t3;
            }
            t2=tmp;
        }
        t2.next=cur;
        return t1.next;
    }
}
